<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>增加用户</title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="<%=path%>/resources/css/reset.css"
	type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="<%=path%>/resources/css/Addstyle.css"
	type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="<%=path%>/resources/css/invalid.css"
	type="text/css" media="screen" />
<link type="text/css"
	href="<%=path%>/resources/date/jquery.datepick.css" rel="stylesheet" />
<style type="text/css">
.itijiao {
	border-right: #7b9ebd 1px solid;
	padding-right: 2px;
	border-top: #7b9ebd 1px solid;
	padding-left: 2px;
	font-size: 12px;
	filter: progid:dximagetransform.microsoft.gradient(gradienttype=0,
		startcolorstr=#ffffff, endcolorstr=#cecfde );
	border-left: #7b9ebd 1px solid;
	cursor: hand;
	color: black;
	padding-top: 2px;
	border-bottom: #7b9ebd 1px solid;
	width: 80px;
	height: 30px
}
</style>
</head>
<body>
	<div id="body-wrapper">
		<div id="main-content">
			<div class="clear"></div>
			<!-- End .clear -->
			<div class="content-box">
				<div class="content-box-content">
					<div id="tab2" style="display: inline;">
						<form action="addUser.action" method="post">
							<fieldset>
								<br />
								<div style="font-size:14px;color:blue;font-weight: bold">人员信息</div>
								<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
								<p>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;类型：
									<s:select name="report.reporttype"
										cssStyle="width:163px;height:30px" list="#request.userTypeMap"
										id="user_type" listKey="key" listValue="value"
										value="user.type" headerKey="0" headerValue="请选择"></s:select>
									<br />
								</p>
								<p>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名：
									<s:textfield cssClass="text-input small-input" id="user_name"
										name="user.name"></s:textfield>
									<br />
								</p>
								<p id="sysUserP">
									&nbsp;&nbsp;&nbsp;登录名：
									<s:textfield cssClass="text-input small-input"
										id="user_loginname" name="user.loginname" />
									<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码：
									<s:password cssClass="text-input small-input"
										id="user_password" name="user.password" />
									<br /> <br /> 重复密码：
									<s:password cssClass="text-input small-input"
										id="user_passwordAgain" name="user.password" />

									&nbsp;&nbsp;&nbsp;&nbsp; <br /> <input type="hidden"
										name="user.uid" id="user_uid"
										value='<s:property value="user.uid"/>' />
								</p>

								<p>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注：
									<s:textfield cssClass="text-input small-input" id="user_desc"
										name="user.descs" />
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
								</p>
								<p>
									<input class="itijiao" id="ibtn" type="button" value="新    增" />
								</p>
							</fieldset>
							<div class="clear"></div>
						</form>
					</div>
				</div>
			</div>

		</div>
	</div>
</body>
</html>
<script type="text/javascript"
	src="<%=path%>/resources/scripts/jquery-1.8.3.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/resources/date/jquery.datepick.js"></script>
<script type="text/javascript"
	src="<%=path%>/resources/date/jquery.datepick-zh-CN.js"></script>

<!-- jQuery Configuration -->
<script type="text/javascript"
	src="<%=path%>/resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript"
	src="<%=path%>/resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript"
	src="<%=path%>/resources/scripts/jquery.wysiwyg.js"></script>
<script type="text/javascript" language="javascript">
	//改变按钮的名称
	$(document).ready(function() {
		var userId = $("#user_uid").val();
		//如果是点击列表的修改按钮过来的，则根据用户类型显示
		var selectVal = $("#user_type").val();
		//系统用户
		if (4 == selectVal) {
			$("#sysUserP").show();
		} else {
			$("#sysUserP").hide();
		}
		if (userId == '') {
			$("#ibtn").val("新    增");
		} else {
			$("#ibtn").val("修    改");
		}
	});

	//根据
	$(document).ready(function() {
		//聚焦用户名
		$("#user_name").focus();
		$("#user_type").change(function() {
			var selectVal = $(this).val();
			//系统用户
			if (4 == selectVal) {
				$("#sysUserP").show();
			} else {
				$("#sysUserP").hide();
			}
		});
	});
	/**
	 * function synAddMod() {
	 var url = "synAddMod.action";
	 var params = {
	 "user.logName" : $("#name").attr("value"),
	 "user.password" : $("#password").attr("value")
	 };

	 $.getJSON(url, params, function callback(data) {
	 // convert to json object   
	 var user = eval("(" + data + ")");//   
	 $("#result").each(function() {
	 $(this).html('welcome ,' + user.name);
	 });
	 });
	 }
	 */

	$(function() {
		$("#ibtn").click(
				function() {
					var uid = $("#user_uid").val();
					var params;
					var selectVal = $("#user_type").val();
					if (-1 == selectVal) {
						alert("请选择用户 类型");
					}
					//系统用户
					if (4 == selectVal) {
						//只有新增时的才会出现密码
						//比较两次输入密码是否一致
						if ($("#user_password").val() != $("#user_passwordAgain").val()) {
							alert("两次输入密码不一致,请重新输入");
							$("#user_password").val("");
							$("#user_passwordAgain").val("");
							$("#user_password").focus();
							return;
						}
						params = {
							"user.name" : $("#user_name").val(),
							"user.loginname" : $("#user_loginname").val(),
							"user.password" : $("#user_password").val(),
							"user.type" : $("#user_type").val(),
							"user.uid" : uid,
							"user.desc" :$("#user_desc").val(),
							"user.repetpassword" :$("#user_passwordAgain").val()
						};
					} else {
						params = {
							"user.name" : $("#user_name").val(),
							"user.loginname" : $("#user_loginname").val(),
							"user.type" : $("#user_type").val(),
							"user.uid" : $("#user_uid").val()
						};
					}

					$.ajax({
						type : "POST",
						url : "synAddMod.action",
						data : params,
						dataType : "json", //ajax返回值设置为text（json格式也可用它返回，可打印出结果，也可设置成json）
						success : function(data) {
							//alert(data);
							//var obj = $.parseJSON(data); //使用这个方法解析data
							//var state_value = obj.result; //result是和action中定义的result变量的get方法对应的
							//alert(state_value);
							if ('0' == data) {
								if (uid!='') {
									alert('修改成功');
								} else {
									alert('新增成功');
								}
								window.location.href="userPage.action";
							} else if ('1' == data) {
								if (uid!='') {
									alert('修改失败');
								} else {
									alert('新增失败');
								}
							}
						},
						error : function(json) {
							alert("json=" + json);
							return false;
						}
					});
				});
	});

	
</script>